//
//  LSExponentVController.m
//  LookScore
//
//  Created by wr on 2017/12/5.
//  Copyright © 2017年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSExponentVController.h"
#import "LSCustomHeaderView.h"
#import "LSMatchExponentCell.h"
#import "LSMatchExponentDataVController.h"//指数详情
#import "LSExponentModel.h"
#import "LSAIHistoricaModel.h"
#import "UICustomDatePicker.h"
#import "LSLiveCompetitionViewController.h"
#import "LSDataLeagueModel.h"
#import <AsyncDisplayKit/AsyncDisplayKit.h>
#import "LSExponentNode.h"
@interface LSExponentVController ()<ASTableDelegate,ASTableDataSource>

//<UITableViewDelegate,UITableViewDataSource>

@property(strong,nonatomic)UITableView *tableView;

//比赛模型数组
@property(strong,nonatomic)NSMutableArray *modelArray;

//公司模型数组
@property (nonatomic, strong) NSMutableArray * companyArray;

@property (nonatomic, strong) NSMutableArray * aIHistoricaDataArray;

@property (nonatomic, strong) NSMutableArray * oddsChangeRecordDataArray;

@property (nonatomic, strong) NSMutableArray * sDHistoricaDataArray;

//选中的公司模型数组
@property (nonatomic, strong) NSMutableArray * selectCompanyArray;
//数据类型 欧赔 亚盘 大小球
@property (nonatomic, copy) NSString * dataType;

@property (nonatomic, strong) id responseObject;
@property (nonatomic, copy) NSString * headerLabelStr;
/** */
@property (nonatomic, copy) NSString *dateStr;
@property (nonatomic, assign) NSInteger type;

@property (nonatomic, copy) NSString * opArray;
@property (nonatomic, copy) NSString * ypArray;
@property (nonatomic, strong) NSMutableArray *leagArray;
@property (nonatomic, strong) NSMutableArray * modelCopyArray;

@property (nonatomic, strong) ASTableNode * tableNode;
@end

@implementation LSExponentVController{
    LSExponentList * _model;
    NSIndexPath * selectIndex;
    BOOL isopen;
    
}
- (NSMutableArray *)leagArray{
    if (!_leagArray) {
        _leagArray = @[].mutableCopy;
    }
    return _leagArray;
}
- (NSMutableArray *)companyArray{
    if (!_companyArray) {
        _companyArray = @[].mutableCopy;
    }
    return _companyArray;
}

- (NSMutableArray *)aIHistoricaDataArray{
    if (!_aIHistoricaDataArray) {
        _aIHistoricaDataArray = @[].mutableCopy;
    }
    return _aIHistoricaDataArray;
}
- (NSMutableArray *)oddsChangeRecordDataArray{
    if (!_oddsChangeRecordDataArray) {
        _oddsChangeRecordDataArray = @[].mutableCopy;
    }
    return _oddsChangeRecordDataArray;
}

- (NSMutableArray *)sDHistoricaDataArray{
    if (!_sDHistoricaDataArray) {
        _sDHistoricaDataArray = @[].mutableCopy;
    }
    return _sDHistoricaDataArray;
}

//-(UITableView *)tableView{
//    if (!_tableView) {
//        _tableView = [[UITableView alloc]init];
//        _tableView.delegate = self;
//        _tableView.dataSource = self;
//        _tableView.backgroundColor =LSSubGrayColorf7;
//        _tableView.showsVerticalScrollIndicator = NO;
////        _tableView.sectionHeaderHeight=0;
//        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//    }
//    return _tableView;
//}

- (ASTableNode *)tableNode{
    if (!_tableNode) {
        _tableNode = [[ASTableNode alloc] initWithStyle:UITableViewStylePlain];
        _tableNode.view.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableNode.delegate = self;
        _tableNode.dataSource = self;
        _tableNode.backgroundColor = [UIColor groupTableViewBackgroundColor];
        
    }
    return _tableNode;
}



-(NSMutableArray *)modelArray{
    if(!_modelArray){
        _modelArray=[[NSMutableArray alloc]init];
    }
    return _modelArray;
}
- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    self.tableNode.frame = self.view.bounds;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _dataType = @"yp";
    self.title=@"指数";
    _opArray = @"80|281|1183";
    _ypArray = @"8|1|45";
    _type = 0;
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.imageArray=@[@"NavFiltrate",@"NavSetting",@"NavDataBank"];
    _headerLabelStr = [NSString stringWithFormat:@"%@ %@",[CommonClass readCurrentTimeString],[CommonClass readWeekDay]];
    _dateStr = [CommonClass readCurrentTimeString];
    
    //本界面采用Facebook的开源库Textrue的ASTableNode 代替原生的UITableView。 具体请看https://didee.cn/2018/01/29/iOS-ASDK/
    [self.view addSubnode:self.tableNode];
    [self initPagerView];
    //    [self loadData:YES withDateStr:_dateStr with:_type];
    
    
    LSRefreshHeaderView *header = [LSRefreshHeaderView headerWithRefreshingBlock:^{
        [self loadData:YES withDateStr:_dateStr with:_type];
    }];
    //    self.tableView.mj_header = header;// 设置header
    self.tableNode.view.mj_header = header;
    [header beginRefreshing];
    
    
    NSArray * array = @[@{@"CompanyName":@"澳门",@"YP":@"1",@"OP":@"80",@"isSelected":@(1)},@{@"CompanyName":@"bet356",@"YP":@"8",@"OP":@"281",@"isSelected":@(1)},@{@"CompanyName":@"ManbetX",@"YP":@"45",@"OP":@"1183",@"isSelected":@(1)},@{@"CompanyName":@"易胜博",@"YP":@"12",@"OP":@"90",@"isSelected":@(0)},@{@"CompanyName":@"利记",@"YP":@"31",@"OP":@"474",@"isSelected":@(0)}];
    for (NSDictionary * dict in array) {
        CompanyList * model = [CompanyList mj_objectWithKeyValues:dict];
        [self.companyArr addObject:model];
    }
    
}
#pragma mark --加载数据源
- (void)loadData:(BOOL)refresh withDateStr:(NSString *)dateStr with:(NSInteger)type{
    
    [LSHttpEnclosureTool GET:LSDATABASERASIANMATCHINDEX parameters:nil resBlock:^(id responseObject) {
//        MyLog(@"%@",responseObject[@"DataLeagueList"]);
        
        if (responseObject) {
            if (refresh) {
                [self.modelArray removeAllObjects];
                [self.leagArray removeAllObjects];
            }
            for (NSDictionary *dict1 in responseObject[@"AsianPlatePageList"]) {
                LSExponentList *  model = [LSExponentList mj_objectWithKeyValues:dict1];
                model.isSelected = YES;
                [self.modelArray addObject:model];
            }
            self.modelCopyArray = self.modelArray.mutableCopy;
            [self endRefreshing];
            [self.tableNode reloadData];
            NSIndexPath *firstPath = [NSIndexPath indexPathForRow:0 inSection:0];
            [self.tableNode selectRowAtIndexPath:firstPath animated:YES scrollPosition:UITableViewScrollPositionNone];
            if ([self.tableNode.delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) {
                //                [self.tableNode.delegate tableView:self.tableView didSelectRowAtIndexPath:firstPath];
                [self.tableNode.delegate tableNode:self.tableNode didSelectRowAtIndexPath:firstPath];
            }
            for (NSDictionary *dict in responseObject[@"DataLeagueList"]) {
                LSDataLeagueModel * model = [LSDataLeagueModel mj_objectWithKeyValues:dict];
                [self.leagArray addObject:model];
            }
            self.leagueArray = self.leagArray.mutableCopy;
//            MyLog(@"%ld",self.leaArray.count);
            
        }else{
            
            [self endRefreshing];
            [self.tableNode reloadData];
        }
    }];
    
    
}

#pragma mark --排列数据
- (void)arrangementData:(NSMutableDictionary *)responseObject withArrayNameStr:(NSString *)name{
    
    NSMutableArray * array = [NSMutableArray arrayWithArray:responseObject[name]];
    NSMutableArray *dateMutablearray = [@[] mutableCopy];
    
    for (NSInteger i = 0; i<array.count; i++) {
        NSDictionary * dict = array[i];
        NSMutableArray *tempArray = [@[] mutableCopy];
        [tempArray addObject:dict];
        for (NSInteger j = i + 1; j < array.count; j++) {
            NSMutableDictionary * dict1 = array[j];
            if ([dict[@"CompanyId"] integerValue] == [dict1[@"CompanyId"] integerValue] && [dict[@"CompanyName"] isEqualToString:dict1[@"CompanyName"]] && [dict[@"MatchId"] isEqualToString:dict1[@"MatchId"]] ) {
                [tempArray addObject:dict1];
                [array removeObjectAtIndex:j];
                j -= 1;
            }
        }
        [dateMutablearray addObject:@{@"companyDataList":tempArray,@"CompanyId":dict[@"CompanyId"],@"CompanyName":dict[@"CompanyName"],@"MatchId":dict[@"MatchId"]}];
    }
    
    [responseObject setObject:dateMutablearray forKey:name];
    
}
- (void)changLeagueNameArray:(NSMutableArray *)leagueNameArray{
    NSMutableArray * deleteModelArr = @[].mutableCopy;
    self.modelArray = self.modelCopyArray.mutableCopy;
    for (LSExponentList * model in self.modelArray) {
        BOOL isHas = YES;
        for (NSString * name  in leagueNameArray) {
            if ([name isEqualToString:model.LeagueName]) {
                isHas = NO;
            }
        }
        if (isHas) {
            
            [deleteModelArr addObject:model];
        }
    }
    [self.modelArray removeObjectsInArray:deleteModelArr];
    [self.tableView reloadData];
}
//
- (void)changeValue:(NSMutableArray *)companyArr{

////    CompanyList * model = companyArr.firstObject;
////    MyLog(@"%ld",model.CompanyId);
//    [self.modelArray removeAllObjects];
//    for (NSDictionary * dict in self.responseObject[@"AsianPlatePageList"]) {
//        NSMutableDictionary * dict1 = dict.mutableCopy;
//        [self arrangementData:dict1 withArrayNameStr:@"AIHistoricaDataList" withCompanyModelArray:companyArr] ;
//
//        [self arrangementData:dict1 withArrayNameStr:@"OddsChangeRecordList" withCompanyModelArray:companyArr];
//        [self arrangementData:dict1 withArrayNameStr:@"SDHistoricaDataList" withCompanyModelArray:companyArr];
//
//        LSExponentModel * model = [LSExponentModel mj_objectWithKeyValues:dict1];
//
//
//        [self.modelArray addObject:model];
////                        MyLog(@"%@",dict1);
//    }
//    [self.tableView reloadData];
//    self.companyArr = self.companyArray;
   __block NSString * ypStr = @"";
   __block NSString * opStr = @"";


    [companyArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        CompanyList * model = obj;
        if (idx == 0) {
            ypStr = [ypStr stringByAppendingString:[NSString stringWithFormat:@"%@",model.YP]];
            opStr = [opStr stringByAppendingString:[NSString stringWithFormat:@"%@",model.OP]];
        }else{
            ypStr = [ypStr stringByAppendingString:[NSString stringWithFormat:@"|%@",model.YP]];
            opStr = [opStr stringByAppendingString:[NSString stringWithFormat:@"|%@",model.OP]];
            
        }
    }];
    _opArray = opStr;
    _ypArray = ypStr;
    [self loadExpontData:[NSString stringWithFormat:@"%ld",(long)_model.MatchId] withModel:_model];
    MyLog(@"%@",ypStr);
}

//
//
//- (void)arrangementData:(NSMutableDictionary *)responseObject withArrayNameStr:(NSString *)name withCompanyModelArray:(NSMutableArray *)modelArray{
//
//    NSMutableArray * array = [NSMutableArray arrayWithArray:responseObject[name]];
//    NSMutableArray *dateMutablearray = [@[] mutableCopy];
//
//    for (NSInteger i = 0; i<array.count; i++) {
//        NSDictionary * dict = array[i];
//        NSMutableArray *tempArray = [@[] mutableCopy];
//        [tempArray addObject:dict];
//        for (NSInteger j = i + 1; j < array.count; j++) {
//            NSMutableDictionary * dict1 = array[j];
//            if ([dict[@"CompanyId"] integerValue] == [dict1[@"CompanyId"] integerValue] && [dict[@"CompanyName"] isEqualToString:dict1[@"CompanyName"]] && [dict[@"MatchId"] isEqualToString:dict1[@"MatchId"]]) {
//                [tempArray addObject:dict1];
//                [array removeObjectAtIndex:j];
//                j -= 1;
//            }
//        }
//
//        if (modelArray.count == 0 || modelArray == nil) {
//            [dateMutablearray addObject:@{@"companyData":tempArray,@"CompanyId":dict[@"CompanyId"],@"CompanyName":dict[@"CompanyName"],@"MatchId":dict[@"MatchId"]}];
//        }else{
//            for (CompanyList * model in modelArray) {
//                MyLog(@"%ld",[dict[@"CompanyId"] integerValue]);
//                if (model.CompanyId == [dict[@"CompanyId"] integerValue]) {
//                    [dateMutablearray addObject:@{@"companyData":tempArray,@"CompanyId":dict[@"CompanyId"],@"CompanyName":dict[@"CompanyName"],@"MatchId":dict[@"MatchId"]}];
//                }
//            }
//        }
//
//    }
//    [responseObject setObject:dateMutablearray forKey:name];
//}


#pragma mark --ASTableDelegate,ASTableDataSource

- (NSInteger)tableNode:(ASTableNode *)tableNode numberOfRowsInSection:(NSInteger)section{
    
    return self.modelArray.count;
}

- (ASCellNodeBlock )tableNode:(ASTableNode *)tableNode nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath{
    LSExponentList * model = self.modelArray[indexPath.row];
    return ^{
        // 4
        LSExponentNode *node = [[LSExponentNode alloc] initWithExpont:model];
        node.selectionStyle = UITableViewCellSelectionStyleNone;
        node.ClickCheckMoreBtnBlock = ^{
            //            LSExponentList * model = self.modelArray[indexPath. row];
            LSLiveCompetitionViewController * liveVC = [[LSLiveCompetitionViewController alloc] init];
            liveVC.matchId = model.MatchId;
            liveVC.selectIndex = 3;
            [self.navigationController pushViewController:liveVC animated:YES];
        };
        //You'll add something extra here later...
        return node;
    };
}
- (void)tableNode:(ASTableNode *)tableNode didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    isopen = NO;
    if (selectIndex != nil && selectIndex.row != indexPath.row) {
        
        LSExponentList * model = self.modelArray[selectIndex.row];
        model.isOpen = isopen;
        [self.tableNode reloadRowsAtIndexPaths:@[selectIndex] withRowAnimation:UITableViewRowAnimationFade];
    }
    
    selectIndex = indexPath;
    LSExponentList * model = self.modelArray[indexPath.row];
    
    isopen = model.isOpen;
    model.isOpen = !model.isOpen;
    
    _model = model;
    [tableNode selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
    [self.tableNode reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    NSString *matchIdStr = [NSString stringWithFormat:@"%ld",(long)model.MatchId];
    NSLog(@"matchIdStr -- %@",matchIdStr);
    if (model.isOpen) {
        //        [self loadExpontData:matchIdStr];
        MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
        //    hud.label.text=@"正在请求中...";
        hud.mode=MBProgressHUDModeIndeterminate;
        [LSHttpEnclosureTool GET:LSDATABASERASIANINDEX parameters:@{@"matchId":matchIdStr,@"ypArray":_ypArray,@"opArray":_opArray} resBlock:^(id responseObject) {
            //            MyLog(@"%@",responseObject);
            [hud hideAnimated:YES];
            if (responseObject) {
                [self.oddsChangeRecordDataArray removeAllObjects];
                [self.aIHistoricaDataArray removeAllObjects];
                [self.sDHistoricaDataArray removeAllObjects];
                
                NSDictionary * dict = responseObject;
                NSMutableDictionary * dict1 = dict.mutableCopy;
                [self arrangementData:dict1 withArrayNameStr:@"AIHistoricaDataList"];
                [self arrangementData:dict1 withArrayNameStr:@"OddsChangeRecordList"];
                [self arrangementData:dict1 withArrayNameStr:@"SDHistoricaDataList"];
                //                MyLog(@"%@",dict1);
                for (NSDictionary *aiDic in dict1[@"AIHistoricaDataList"]) {
                    LSAIHistoricaModel * aiModel = [LSAIHistoricaModel mj_objectWithKeyValues:aiDic];
                    [self.aIHistoricaDataArray addObject:aiModel];
                }
                for (NSDictionary *OddDic in dict1[@"OddsChangeRecordList"]) {
                    LSOddsChangeRecordModel * oddModel = [LSOddsChangeRecordModel mj_objectWithKeyValues:OddDic];
                    [self.oddsChangeRecordDataArray addObject:oddModel];
                }
                
                for (NSDictionary *SDDic in dict1[@"SDHistoricaDataList"]) {
                    LSSDHistoricaModel * sdModel = [LSSDHistoricaModel mj_objectWithKeyValues:SDDic];
                    [self.sDHistoricaDataArray addObject:sdModel];
                }
                model.OddsChangeRecordList = self.oddsChangeRecordDataArray.mutableCopy;
                model.AIHistoricaDataList = self.aIHistoricaDataArray.mutableCopy;
                model.SDHistoricaDataList = self.sDHistoricaDataArray.mutableCopy;
                [self.tableNode reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
            }
        }];
    }
}

- (void)tableNode:(ASTableNode *)tableNode didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
    LSExponentModel * model = self.modelArray[indexPath.row];
    model.isOpen = !model.isOpen;
    [tableNode deselectRowAtIndexPath:indexPath animated:YES];// 取消选中
    [tableNode reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

#pragma mark 🔥 tableViewDelegate tableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.modelArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    LSExponentList *model = self.modelArray[indexPath.row];
    return model.cellHeight;
    //    return 87+11+60*3+3+8;//  tableView.rowHeight;
}


- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    LSMatchExponentCell *cell=[LSMatchExponentCell MatchExponentTableviewCellByTableView:tableView];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = self.modelArray[indexPath.row];
    cell.ClickCheckMoreBtnBlock = ^{
        MyLog(@"查看更多");
        
        LSExponentList * model = self.modelArray[indexPath.row];
        LSLiveCompetitionViewController * liveVC = [[LSLiveCompetitionViewController alloc] init];
        liveVC.matchId = model.MatchId;
        liveVC.selectIndex = 3;
        [self.navigationController pushViewController:liveVC animated:YES];
        
        
    };
    return cell;
}




//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    
//    LSCustomHeaderView *_Nullable headerView=[tableView dequeueReusableHeaderFooterViewWithIdentifier:@"CompetitionActionListView"];
//
//    if (!headerView) {
//        headerView = [[LSCustomHeaderView alloc]initWithReuseIdentifier:@"CompetitionActionListView" style:KTableViewHeaderTitleStyle];
//    }
//    headerView.contentView.backgroundColor=[UIColor whiteColor];
//    headerView.timeLab.attributedText=[CommonClass setTitle:_headerLabelStr color:LSTitleGrayColor2];
//    headerView.timeLab.userInteractionEnabled = YES;
//    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
//    [headerView.timeLab addGestureRecognizer:tap];
    
//}


 //some functions ...... // 取消选状态 [tableView deselectRowAtIndexPath:indexPa...

//- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
//    [_tableView reloadRowsAtIndexPaths:@[selectIndexPath] withRowAnimation:UITableViewRowAnimationFade];
//    return selectIndexPath;
//}
//
//- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
//    MyLog(@"1");
//}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    isopen = NO;
    if (selectIndex != nil && selectIndex.row != indexPath.row) {
        
        LSExponentList * model = self.modelArray[selectIndex.row];
        model.isOpen = isopen;
        [_tableView reloadRowsAtIndexPaths:@[selectIndex] withRowAnimation:UITableViewRowAnimationFade];
    }
    
    selectIndex = indexPath;
    LSExponentList * model = self.modelArray[indexPath.row];
    
    isopen = model.isOpen;
    model.isOpen = !model.isOpen;
    
    _model = model;
    [tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
    [_tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    NSString *matchIdStr = [NSString stringWithFormat:@"%ld",(long)model.MatchId];
    //    NSString *matchIdStr = [NSString stringWithFormat:@"%zd",1412542];
    
    //    [_tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    
    
    MyLog(@"matchIdStr -- %@",matchIdStr);
    if (model.isOpen) {
        //        [self loadExpontData:matchIdStr];
        MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
        //    hud.label.text=@"正在请求中...";
        hud.mode=MBProgressHUDModeIndeterminate;
        [LSHttpEnclosureTool GET:LSDATABASERASIANINDEX parameters:@{@"matchId":matchIdStr,@"ypArray":_ypArray,@"opArray":_opArray} resBlock:^(id responseObject) {
            //            MyLog(@"%@",responseObject);
            [hud hideAnimated:YES];
            if (responseObject) {
                [self.oddsChangeRecordDataArray removeAllObjects];
                [self.aIHistoricaDataArray removeAllObjects];
                [self.sDHistoricaDataArray removeAllObjects];
                
                NSDictionary * dict = responseObject;
                NSMutableDictionary * dict1 = dict.mutableCopy;
                [self arrangementData:dict1 withArrayNameStr:@"AIHistoricaDataList"];
                [self arrangementData:dict1 withArrayNameStr:@"OddsChangeRecordList"];
                [self arrangementData:dict1 withArrayNameStr:@"SDHistoricaDataList"];
                //                MyLog(@"%@",dict1);
                for (NSDictionary *aiDic in dict1[@"AIHistoricaDataList"]) {
                    LSAIHistoricaModel * aiModel = [LSAIHistoricaModel mj_objectWithKeyValues:aiDic];
                    [self.aIHistoricaDataArray addObject:aiModel];
                }
                for (NSDictionary *OddDic in dict1[@"OddsChangeRecordList"]) {
                    LSOddsChangeRecordModel * oddModel = [LSOddsChangeRecordModel mj_objectWithKeyValues:OddDic];
                    [self.oddsChangeRecordDataArray addObject:oddModel];
                }
                
                for (NSDictionary *SDDic in dict1[@"SDHistoricaDataList"]) {
                    LSSDHistoricaModel * sdModel = [LSSDHistoricaModel mj_objectWithKeyValues:SDDic];
                    [self.sDHistoricaDataArray addObject:sdModel];
                }
                model.OddsChangeRecordList = self.oddsChangeRecordDataArray.mutableCopy;
                model.AIHistoricaDataList = self.aIHistoricaDataArray.mutableCopy;
                model.SDHistoricaDataList = self.sDHistoricaDataArray.mutableCopy;
                [self.tableView reloadData];
            }
        }];
    }
}



- (void)ComparisonOfModelSizeWith:(companyDataList *)latestComModel With:(companyDataList *)cacelComModel withType:(NSString *)type{
    
    
}


- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
    LSExponentModel * model = self.modelArray[indexPath.row];
    model.isOpen = !model.isOpen;
    [tableView deselectRowAtIndexPath:indexPath animated:YES];// 取消选中
    [_tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}


- (void)loadExpontData:(NSString *)matchId withModel:(LSExponentList *)model{
    
    //    MyLog(@"yp = %@",_ypArray);
    //    MyLog(@"op = %@",_opArray);
    [LSHttpEnclosureTool GET:LSDATABASERASIANINDEX parameters:@{@"matchId":matchId,@"ypArray":_ypArray,@"opArray":_opArray} resBlock:^(id responseObject) {
        //        MyLog(@"%@",responseObject);
        if (responseObject) {
            [self.oddsChangeRecordDataArray removeAllObjects];
            [self.aIHistoricaDataArray removeAllObjects];
            [self.sDHistoricaDataArray removeAllObjects];
            NSDictionary * dict = responseObject;
            NSMutableDictionary * dict1 = dict.mutableCopy;
            [self arrangementData:dict1 withArrayNameStr:@"AIHistoricaDataList"];
            [self arrangementData:dict1 withArrayNameStr:@"OddsChangeRecordList"];
            [self arrangementData:dict1 withArrayNameStr:@"SDHistoricaDataList"];
            //            MyLog(@"%@",dict1);
            for (NSDictionary *aiDic in dict1[@"AIHistoricaDataList"]) {
                LSAIHistoricaModel * aiModel = [LSAIHistoricaModel mj_objectWithKeyValues:aiDic];
                [self.aIHistoricaDataArray addObject:aiModel];
            }
            
            for (NSDictionary *OddDic in dict1[@"OddsChangeRecordList"]) {
                LSOddsChangeRecordModel * oddModel = [LSOddsChangeRecordModel mj_objectWithKeyValues:OddDic];
                [self.oddsChangeRecordDataArray addObject:oddModel];
            }
            
            for (NSDictionary *SDDic in dict1[@"SDHistoricaDataList"]) {
                LSSDHistoricaModel * oddModel = [LSSDHistoricaModel mj_objectWithKeyValues:SDDic];
                [self.sDHistoricaDataArray addObject:oddModel];
            }
            model.OddsChangeRecordList = self.oddsChangeRecordDataArray.mutableCopy;
            model.AIHistoricaDataList = self.aIHistoricaDataArray.mutableCopy;
            model.SDHistoricaDataList = self.sDHistoricaDataArray.mutableCopy;
            [self.tableView reloadData];
        }
    }];
    
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    //    [self.tableView reloadData];
}



//- (void)tapAction:(UITapGestureRecognizer *)tap{
//
//    [UICustomDatePicker showCustomDatePickerAtView:[UIApplication sharedApplication].keyWindow choosedDateBlock:^(NSDate *date) {
//
//        NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init];
//        [dateFormat setDateFormat:@"yyyy-MM-dd"];
//        NSString* string=[dateFormat stringFromDate:date];
//        _dateStr = string;
//        [self loadData:YES withDateStr:_dateStr with:_type];
//        _headerLabelStr = [NSString stringWithFormat:@"%@ %@",string,[CommonClass readWeekDayWith:date]];
//        MyLog(@"current Date:%@",string);
//    } cancelBlock:^{
//
//    }];
//
//}


#pragma mark 🔥 UI
-(void)initPagerView{
    
    

//    LSTopSegmentSortView *segmentView=[[LSTopSegmentSortView alloc]initWithFrame:CGRectMake(LSAutoVlaue(60, LSScreenWidth), 0, LSScreenWidth-LSAutoVlaue(60, LSScreenWidth)*2, 35)];
//    segmentView.unSelectedColor=LSTitleWhiteColor;
//    segmentView.selectedColor=LSNavTitlenColor;
//    [segmentView addBottomArray:@[@"欧赔",@"亚盘",@"大小球"] selectButton:1];
//    [aboveView addSubview:segmentView];
//    segmentView.butonActionBlock = ^(NSInteger tag) {
//       switch (tag) {
//           case 0:{
//               self.dataType = @"op";
//               self.type = 1;
//
//           }
//               break;
//           case 1:{
//               self.dataType = @"yp";
//               self.type = 0;
//           }
//
//               break;
//           case 2:{
//               self.dataType = @"dxq";
//               self.type = 2;
//
//           }
//             break;
//            default:
//               break;
//
//       }
//
//            MyLog(@"%ld",tag);
//        [self.tableView reloadData];
//        [self loadData:YES withDateStr:_dateStr with:_type];
//    };
//
    [self.view addSubview:self.tableView];
//    self.tableView.sd_layout.leftEqualToView(self.view).topEqualToView(self.view).rightEqualToView(self.view).bottomEqualToView(self.view);

    //    self.tableView.sd_layout.leftEqualToView(self.view).topEqualToView(self.view).rightEqualToView(self.view).bottomEqualToView(self.view);

    
}


- (void)endRefreshing{
    if ([self.tableNode.view.mj_header isRefreshing]) {
        [self.tableNode.view.mj_header endRefreshing];
    }else if([self.tableNode.view.mj_footer isRefreshing]){
        [self.tableNode.view.mj_footer endRefreshing];
        
    }
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end

